export const namespace = "coursePersonalOrder";
import { vipTypeList } from "@/utils/common";
import { Flex, Typography, Image, Space, Tag } from "antd";
import default_avater from "@/assets/imgs/default_avater.png";
import default_avater_female from "@/assets/imgs/default_avater_female.png";
import dayjs from "dayjs";
import { getItem } from "@/utils/localstorage";
import Https from "@/utils/Https";
const { Text } = Typography;
const coachRequest = async () => {
  let params = {
    venueId: getItem("venueInfo").id,
  };
  let res: any = await Https.get("/employee/manage/listCoach", params, true);
  let objList = [];
  if (res.code == 200 && res.data) {
    if (res.data.length > 0) {
      res.data.map((e) => objList.push({ label: e.nickName, value: e.userId }));
    }
  }
  return objList;
};
export const calcColumns = (params) => {
  const { operate } = params;
  const columns = [
    {
      title: "课程名称",
      dataIndex: "courseName",
      ellipsis: true,
      width: 200,
    },
    // {
    //   title: "所属场馆",
    //   dataIndex: "venueName",
    //   hideInSearch: true,
    //   ellipsis: true,
    // },
    {
      title: "课程教练",
      dataIndex: "courseCoachName",
      request: coachRequest,
      search: {
        transform: (e) => {
          const courseCoachId = e;
          return {
            courseCoachId,
          };
        },
      },
    },
    {
      title: "课程时长",
      dataIndex: "courseDuration",
      hideInSearch: true,
      ellipsis: true,
      render: (_, record) => {
        return (
          <span>
            {record.courseDuration ? record.courseDuration + "分钟" : "-"}
          </span>
        );
      },
    },
  ];

  columns.push(operate);
  return columns;
};

export const calcColumns2 = (params) => {
  const { operate } = params;
  const columns = [
    {
      title: "会员信息",
      dataIndex: "nickName_tel",
      valueType: "image",
      hideInSearch: true,
      render: (_, record) => {
        const defaultAva =
          record.sex == 0 ? default_avater : default_avater_female;
        return (
          <Flex align="center">
            <div>
              <Image
                style={{ borderRadius: "50%" }}
                width={52}
                src={record.avatar || defaultAva}
              />
            </div>
            <div style={{ marginLeft: "15px" }}>
              <Text>{record.nickName}</Text>
              <br />
              <Text type="secondary">{record.tel}</Text>
            </div>
          </Flex>
        );
      },
    },
    {
      title: "卡信息",
      dataIndex: "vipcardName_cardNo",
      hideInSearch: true,
      render: (_, record) => {
        return (
          <Space direction="vertical" size="small">
            <Text>{record.vipcardName}</Text>
            <Text type="secondary" copyable>
              {record.cardNo}
            </Text>
          </Space>
        );
      },
    },

    // {
    //   title: "昵称",
    //   dataIndex: "nickName",
    //   ellipsis: true,
    // },
    // {
    //   title: "手机号",
    //   dataIndex: "tel",
    // },
    {
      title: "开卡/过期日期",
      hideInSearch: true,
      dataIndex: "publishTime",
      render: (_, record) => {
        return (
          <div>
            <Tag color="blue">开卡</Tag>
            {record.startTime && record.startTime.length > 0
              ? dayjs(record.startTime).format("YYYY-MM-DD")
              : "-"}
            <br />
            <Tag style={{ marginTop: "10px" }} color="error">
              过期
            </Tag>
            {record.effectiveTime && record.effectiveTime.length > 0
              ? dayjs(record.effectiveTime).format("YYYY-MM-DD")
              : "-"}
          </div>
        );
      },
    },
    {
      title: "卡余额",
      dataIndex: "currentCardLimit",
      hideInSearch: true,
      render: (_, record) => {
        return (
          <span>
            {record.vipType != 2
              ? record.vipType == 1
                ? Number(record.currentCardLimit) / 100 +
                  vipTypeList[record.vipType].status
                : record.currentCardLimit + vipTypeList[record.vipType].status
              : "-"}
          </span>
        );
      },
    },
  ];

  columns.push(operate);
  return columns;
};
